package com.dynamixsoftware.printershare;

import android.app.AlertDialog.Builder;
import android.content.ContentResolver;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.BitmapFactory;
import android.graphics.BitmapFactory.Options;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.Picture;
import android.graphics.Rect;
import android.net.Uri;
import android.os.Bundle;
import android.os.Parcelable;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.KeyEvent;
import android.view.MenuItem;
import android.view.View;
import com.dynamixsoftware.printershare.data.Paper;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Vector;

public class ActivityPrintPictures
  extends ActivityPrint
{
  private ArrayList<ImgDat> data = new ArrayList();
  private boolean external;
  private boolean fp_mode;
  private int sel_size;
  private int size = 3;
  private CharSequence[] sizeOptions;
  private double[] sizeOptionsWH;
  
  private Bitmap decodeBitmap(ImgDat paramImgDat)
  {
    if (paramImgDat.dat == null) {}
    for (;;)
    {
      InputStream localInputStream2;
      FileOutputStream localFileOutputStream;
      try
      {
        String str = paramImgDat.uri.getScheme();
        if (("http".equals(str)) || ("https".equals(str)))
        {
          paramImgDat.dat = new File(App.getTempDir() + "/img_" + Integer.toHexString(paramImgDat.uri.hashCode()) + ".tmp");
          if ("https".equals(paramImgDat.uri.getScheme())) {
            break label272;
          }
          localInputStream2 = getContentResolver().openInputStream(paramImgDat.uri);
          localFileOutputStream = new FileOutputStream(paramImgDat.dat);
          byte[] arrayOfByte = new byte[4096];
          int k = localInputStream2.read(arrayOfByte);
          if (k == -1) {
            break label297;
          }
          localFileOutputStream.write(arrayOfByte, 0, k);
          continue;
        }
        localBitmap = null;
      }
      catch (Exception localException)
      {
        localException.printStackTrace();
        App.reportThrowable(localException);
        paramImgDat.dat = null;
      }
      label179:
      Bitmap localBitmap;
      int i = 0;
      int j = 0;
      if (j < 3) {}
      try
      {
        App.freeMem();
        BitmapFactory.Options localOptions = new BitmapFactory.Options();
        localOptions.inPreferredConfig = Bitmap.Config.ARGB_8888;
        localOptions.inDither = false;
        if (j > 0) {
          localOptions.inSampleSize = (1 << j);
        }
        if (paramImgDat.dat != null) {}
        label272:
        label297:
        InputStream localInputStream1;
        for (Object localObject = new FileInputStream(paramImgDat.dat);; localObject = localInputStream1)
        {
          localBitmap = BitmapFactory.decodeStream((InputStream)localObject, null, localOptions);
          ((InputStream)localObject).close();
          tryAllocateBitmap();
          return localBitmap;
          localInputStream2 = new URL(paramImgDat.uri.toString()).openConnection().getInputStream();
          break;
          localInputStream2.close();
          localFileOutputStream.close();
          break label179;
          localInputStream1 = getContentResolver().openInputStream(paramImgDat.uri);
        }
      }
      catch (IOException localIOException)
      {
        localIOException.printStackTrace();
        App.reportThrowable(localIOException);
        return localBitmap;
      }
      catch (OutOfMemoryError localOutOfMemoryError)
      {
        if (localBitmap != null)
        {
          localBitmap.recycle();
          localBitmap = null;
        }
        if ((i == 0) && (j > 0))
        {
          i = 1;
          App.clearExternalBytesAllocated();
        }
        j++;
      }
    }
  }
  
  private void drawBitmap(Picture paramPicture, Bitmap paramBitmap)
  {
    int i = this.paper.width;
    int j = this.paper.height;
    int k = 0;
    int m = 0;
    int n = 0;
    int i1 = 0;
    if (paramBitmap != null)
    {
      i1 = paramBitmap.getWidth();
      n = paramBitmap.getHeight();
      if ((this.orientation == 2) || ((this.orientation == 0) && (i1 > n)))
      {
        int i11 = i;
        i = j;
        j = i11;
      }
    }
    Canvas localCanvas = paramPicture.beginRecording(i, j);
    localCanvas.drawColor(-1);
    int i3;
    int i4;
    int i5;
    int i6;
    int i7;
    if (paramBitmap != null)
    {
      if (this.margins != 1) {
        break label366;
      }
      i3 = 63;
      i4 = 0;
      i5 = 0;
      if (this.size != 0) {
        break label403;
      }
      i6 = i1 * 254 / 96;
      i7 = n * 254 / 96;
      label143:
      if (!this.fp_mode) {
        break label521;
      }
      if (i6 <= i7) {
        break label491;
      }
      i7 = n * (i - i3 * 2) / i1;
    }
    for (;;)
    {
      Paint localPaint1 = App.newPaint();
      Rect localRect1 = new Rect(k, m, k + i1, m + n);
      localCanvas.drawBitmap(paramBitmap, localRect1, new Rect(i3 + i4, i3 + i5, i6 + (i3 + i4), i7 + (i3 + i5)), localPaint1);
      Paint localPaint2 = App.newPaint();
      localPaint2.setColor(-1);
      localPaint2.setStyle(Paint.Style.FILL);
      Rect localRect2 = new Rect(0, 0, i, i3);
      localCanvas.drawRect(localRect2, localPaint2);
      Rect localRect3 = new Rect(0, j - i3, i, j);
      localCanvas.drawRect(localRect3, localPaint2);
      Rect localRect4 = new Rect(0, 0, i3, j);
      localCanvas.drawRect(localRect4, localPaint2);
      Rect localRect5 = new Rect(i - i3, 0, i, j);
      localCanvas.drawRect(localRect5, localPaint2);
      paramPicture.endRecording();
      return;
      label366:
      if (this.margins == 2)
      {
        i3 = 84;
        break;
      }
      int i2 = this.margins;
      i3 = 0;
      if (i2 != 3) {
        break;
      }
      i3 = 127;
      break;
      label403:
      if (this.size == 1)
      {
        i6 = i - i3 * 2;
        i7 = j - i3 * 2;
        break label143;
      }
      i6 = (int)(254.0D * this.sizeOptionsWH[(2 * this.size)]);
      i7 = (int)(254.0D * this.sizeOptionsWH[(1 + 2 * this.size)]);
      if (i1 <= n) {
        break label143;
      }
      int i8 = i7;
      i7 = i6;
      i6 = i8;
      break label143;
      label491:
      i6 = i1 * (j - i3 * 2) / n;
      i4 = 0;
      i5 = 0;
      k = 0;
      m = 0;
      continue;
      label521:
      label601:
      int i9;
      if (((i6 > i7) && (i6 / i7 <= i1 / n)) || ((i6 <= i7) && (i6 / i7 <= i1 / n)))
      {
        k = n * (i1 * i7 / n - i6) / i7 / 2;
        i1 -= k * 2;
        i9 = i6 - (i - i3 * 2);
        if (i9 >= 0) {
          break label679;
        }
      }
      int i10;
      label679:
      for (i4 = 0;; i4 = -i9 / 2)
      {
        i10 = i7 - (j - i3 * 2);
        if (i10 >= 0) {
          break label689;
        }
        i5 = 0;
        break;
        m = i1 * (n * i6 / i1 - i7) / i6 / 2;
        n -= m * 2;
        k = 0;
        break label601;
      }
      label689:
      i5 = -i10 / 2;
    }
  }
  
  private void tryAllocateBitmap()
  {
    Bitmap localBitmap = Bitmap.createBitmap(512, 512, Bitmap.Config.ARGB_8888);
    if (localBitmap != null) {
      localBitmap.recycle();
    }
  }
  
  protected void createPages()
  {
    if (this.data.size() == 0) {}
    for (;;)
    {
      return;
      this.pages = new Vector();
      Iterator localIterator = this.data.iterator();
      while (localIterator.hasNext())
      {
        ImgDat localImgDat = (ImgDat)localIterator.next();
        this.pages.add(new PicturePage(localImgDat));
      }
    }
  }
  
  protected void endOK()
  {
    if (!this.external)
    {
      this.data.clear();
      onResume();
      return;
    }
    super.endOK();
  }
  
  protected void onActivityResult(int paramInt1, int paramInt2, Intent paramIntent)
  {
    super.onActivityResult(paramInt1, paramInt2, paramIntent);
    if (paramInt1 == 3) {
      if (paramIntent == null) {
        break label55;
      }
    }
    label55:
    for (Uri localUri = paramIntent.getData(); (paramInt2 == -1) && (localUri != null); localUri = null)
    {
      this.data.add(new ImgDat(localUri));
      this.need_update_pages = true;
      return;
    }
    setResult(0);
    finish();
  }
  
  public void onCreate(Bundle paramBundle)
  {
    super.onCreate(paramBundle);
    CharSequence[] arrayOfCharSequence = new CharSequence[8];
    arrayOfCharSequence[0] = getResources().getString(2131099792);
    arrayOfCharSequence[1] = getResources().getString(2131099793);
    arrayOfCharSequence[2] = "3½\"×5\" (9×13 cm)";
    arrayOfCharSequence[3] = "4\"×6\" (10×15 cm)";
    arrayOfCharSequence[4] = "5\"×7\" (13×18 cm)";
    arrayOfCharSequence[5] = "8\"×10\" (20×25 cm)";
    arrayOfCharSequence[6] = "8\"×12\" (20×30 cm)";
    arrayOfCharSequence[7] = "11\"×14\" (28×36 cm)";
    this.sizeOptions = arrayOfCharSequence;
    this.sizeOptionsWH = new double[] { 0.0D, 0.0D, 0.0D, 0.0D, 3.5D, 5.0D, 4.0D, 6.0D, 5.0D, 7.0D, 8.0D, 10.0D, 8.0D, 12.0D, 11.0D, 14.0D };
    this.size = this.prefs.getInt(getActivityClassName() + "#size", this.size);
    Intent localIntent1 = getIntent();
    String str1 = localIntent1.getAction();
    if ("android.intent.action.SEND".equals(str1))
    {
      this.external = true;
      Uri localUri3 = (Uri)localIntent1.getExtras().get("android.intent.extra.STREAM");
      if (localUri3 != null)
      {
        ArrayList localArrayList6 = this.data;
        ImgDat localImgDat5 = new ImgDat(localUri3);
        localArrayList6.add(localImgDat5);
      }
    }
    for (;;)
    {
      return;
      setResult(0);
      finish();
      return;
      if ("android.intent.action.VIEW".equals(str1))
      {
        this.external = true;
        Uri localUri2 = localIntent1.getData();
        if (localUri2 != null)
        {
          ArrayList localArrayList5 = this.data;
          ImgDat localImgDat4 = new ImgDat(localUri2);
          localArrayList5.add(localImgDat4);
          return;
        }
        setResult(0);
        finish();
        return;
      }
      if ("android.intent.action.SEND_MULTIPLE".equals(str1))
      {
        this.external = true;
        ArrayList localArrayList3 = localIntent1.getParcelableArrayListExtra("android.intent.extra.STREAM");
        if ((localArrayList3 == null) || (localArrayList3.size() == 0))
        {
          setResult(0);
          finish();
          return;
        }
        Iterator localIterator = localArrayList3.iterator();
        while (localIterator.hasNext())
        {
          Parcelable localParcelable = (Parcelable)localIterator.next();
          ArrayList localArrayList4 = this.data;
          ImgDat localImgDat3 = new ImgDat((Uri)localParcelable);
          localArrayList4.add(localImgDat3);
        }
      }
      else if ((str1 != null) && (str1.startsWith("com.sec.android.app.mobileprint")))
      {
        this.external = true;
        this.orientation = 0;
        this.size = 1;
        Uri localUri1 = (Uri)localIntent1.getParcelableExtra("android.intent.extra.STREAM");
        if (localUri1 != null)
        {
          Object localObject = localUri1.toString();
          try
          {
            String str4 = URLDecoder.decode((String)localObject, "UTF-8");
            localObject = str4;
            if (((String)localObject).startsWith("file:")) {
              localObject = ((String)localObject).substring(5);
            }
            for (i = 0; ((String)localObject).charAt(i) == '/'; i++) {}
          }
          catch (Exception localException)
          {
            int i;
            for (;;)
            {
              localException.printStackTrace();
              App.reportThrowable(localException);
            }
            if (i > 0)
            {
              File localFile = new File(((String)localObject).substring(i - 1));
              if (localFile.isDirectory())
              {
                this.fp_mode = true;
                File[] arrayOfFile = localFile.listFiles();
                if (arrayOfFile != null) {
                  for (int j = -1 + arrayOfFile.length; j >= 0; j--) {
                    if (arrayOfFile[j].isFile()) {
                      this.data.add(new ImgDat(arrayOfFile[j]));
                    }
                  }
                }
              }
              else
              {
                ArrayList localArrayList1 = this.data;
                ImgDat localImgDat1 = new ImgDat(localFile);
                localArrayList1.add(localImgDat1);
              }
            }
            else
            {
              ArrayList localArrayList2 = this.data;
              ImgDat localImgDat2 = new ImgDat(localUri1);
              localArrayList2.add(localImgDat2);
              return;
            }
          }
        }
      }
    }
    String str2 = localIntent1.getStringExtra("android.intent.extra.SUBJECT");
    String str3 = localIntent1.getStringExtra("android.intent.extra.TEXT");
    setResult(0);
    finish();
    Intent localIntent2 = new Intent("android.intent.action.SEND");
    localIntent2.setClass(this, ActivityWeb.class);
    localIntent2.setType("text/html");
    localIntent2.putExtra("android.intent.extra.TEXT", "<html><head><meta name=\"viewport\" content=\"width=650, target-densitydpi=medium-dpi\"></head><body><font style=\"font-size:14pt\"><b>" + str2 + "</b></font><br><pre style=\"font-size:12pt; padding-top:5px; margin:0; white-space:pre-wrap\">" + str3 + "</pre></body></html>");
    startActivity(localIntent2);
  }
  
  public void onCreateContextMenu(ContextMenu paramContextMenu, View paramView, ContextMenu.ContextMenuInfo paramContextMenuInfo)
  {
    paramContextMenu.setHeaderTitle(getResources().getString(2131099789));
    if (!this.fp_mode) {
      paramContextMenu.add(0, 100, 0, 2131099791);
    }
    paramContextMenu.add(0, 30, 0, 2131099798);
    if (!this.fp_mode) {
      paramContextMenu.add(0, 23, 0, 2131099800);
    }
    paramContextMenu.add(0, 21, 0, 2131099804);
    paramContextMenu.add(0, 22, 0, 2131099805);
    paramContextMenu.add(0, 10, 0, 2131099806);
    paramContextMenu.add(0, 11, 0, 2131099807);
    paramContextMenu.add(0, 12, 0, 2131099651);
  }
  
  public void onDestroy()
  {
    super.onDestroy();
    Iterator localIterator = this.data.iterator();
    while (localIterator.hasNext())
    {
      ImgDat localImgDat = (ImgDat)localIterator.next();
      if ((localImgDat.uri != null) && (localImgDat.dat != null)) {
        localImgDat.dat.delete();
      }
    }
  }
  
  public boolean onKeyDown(int paramInt, KeyEvent paramKeyEvent)
  {
    if (paramInt == 4)
    {
      if (!this.external)
      {
        this.data.clear();
        Intent localIntent = new Intent("android.intent.action.PICK");
        localIntent.setType("image/*");
        startActivityForResult(localIntent, 3);
        return true;
      }
      setResult(0);
    }
    return super.onKeyDown(paramInt, paramKeyEvent);
  }
  
  public boolean onMenuItemSelected(int paramInt, MenuItem paramMenuItem)
  {
    switch (paramMenuItem.getItemId())
    {
    default: 
      return super.onMenuItemSelected(paramInt, paramMenuItem);
    }
    int i = this.paper.width;
    int j = this.paper.height;
    CharSequence[] arrayOfCharSequence;
    for (int k = -1 + this.sizeOptions.length;; k--) {
      if (k > 1)
      {
        int n = (int)(254.0D * this.sizeOptionsWH[(k * 2)]);
        int i1 = (int)(254.0D * this.sizeOptionsWH[(1 + k * 2)]);
        if ((n >= i + 10) || (i1 >= j + 10)) {}
      }
      else
      {
        arrayOfCharSequence = new CharSequence[k + 1];
        for (int m = 0; m <= k; m++) {
          arrayOfCharSequence[m] = this.sizeOptions[m];
        }
      }
    }
    new AlertDialog.Builder(this).setTitle(2131099791).setPositiveButton(2131099703, new DialogInterface.OnClickListener()
    {
      public void onClick(DialogInterface paramAnonymousDialogInterface, int paramAnonymousInt)
      {
        ActivityPrintPictures.access$102(ActivityPrintPictures.this, ActivityPrintPictures.this.sel_size);
        SharedPreferences.Editor localEditor = ActivityPrintPictures.this.prefs.edit();
        localEditor.putInt(ActivityPrintPictures.this.getActivityClassName() + "#size", ActivityPrintPictures.this.size);
        localEditor.commit();
        ActivityPrintPictures.this.need_update_pages = true;
        ActivityPrintPictures.this.update();
      }
    }).setNegativeButton(2131099707, null).setSingleChoiceItems(arrayOfCharSequence, this.size, new DialogInterface.OnClickListener()
    {
      public void onClick(DialogInterface paramAnonymousDialogInterface, int paramAnonymousInt)
      {
        ActivityPrintPictures.access$002(ActivityPrintPictures.this, paramAnonymousInt);
      }
    }).show();
    return true;
  }
  
  protected void onResume()
  {
    Intent localIntent;
    if ((!this.external) && (this.data.size() == 0))
    {
      localIntent = new Intent("android.intent.action.PICK");
      localIntent.setType("image/*");
      if (getPackageManager().queryIntentActivities(localIntent, 0).size() <= 0) {
        break label69;
      }
      startActivityForResult(localIntent, 3);
    }
    for (;;)
    {
      this.need_update_pages = false;
      super.onResume();
      return;
      label69:
      startActivityForResult(Intent.createChooser(localIntent, null), 3);
    }
  }
  
  static final class ImgDat
  {
    File dat;
    Uri uri;
    
    public ImgDat(Uri paramUri)
    {
      this.uri = paramUri;
    }
    
    public ImgDat(File paramFile)
    {
      this.dat = paramFile;
    }
  }
  
  class PicturePage
    extends ActivityPrint.Page
  {
    private ActivityPrintPictures.ImgDat imgDat;
    
    PicturePage(ActivityPrintPictures.ImgDat paramImgDat) {}
    
    public Picture getPicture()
    {
      final Bitmap localBitmap = ActivityPrintPictures.this.decodeBitmap(this.imgDat);
      Picture local1 = new Picture()
      {
        Bitmap cbmp = localBitmap;
        
        protected void finalize()
          throws Throwable
        {
          super.finalize();
          if (this.cbmp != null) {
            this.cbmp = null;
          }
        }
      };
      ActivityPrintPictures.this.drawBitmap(local1, localBitmap);
      return local1;
    }
  }
}


/* Location:           C:\Users\Admin\Desktop\Decompiler\JAD\jd-gui-0.3.6.windows\classes_dex2jar.jar
 * Qualified Name:     com.dynamixsoftware.printershare.ActivityPrintPictures
 * JD-Core Version:    0.7.0.1
 */